package com.lgkj.ui.manager;

import android.widget.EditText;

import com.lgkj.R;
import com.lgkj.ui.BaseActivity;
import com.lgkj.utils.CommonConstant;
import com.lgkj.utils.CommonUtils;
import com.lgkj.utils.HttpUtils;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/6/25 0025.
 */

public class ShopManagerInfoActivity extends BaseActivity {
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_nick)
    EditText etNick;
    @BindView(R.id.et_phpone)
    EditText etPhpone;
    @BindView(R.id.et_adress)
    EditText etAdress;

    @Override
    public int getLayoutId() {
        return R.layout.activity_shop_info;
    }

    @Override
    public void initView() {
        setTitle("店铺信息");
    }

    @Override
    public void initData() {
        showDiaLog("正在获取数据");
        Map<String, String> map = new HashMap<>();
        map.put("access_token", CommonUtils.getToken(ShopManagerInfoActivity.this));
        map.put("barbershop_id", CommonUtils.getShopId(ShopManagerInfoActivity.this));
        HttpUtils.postHttp(map, CommonConstant.barbenshoinfo, new HttpUtils.HttpCallBack() {
            @Override
            public void successHttp(JSONObject jsonObject, int id) {
                dismissDiaLog();
                if (jsonObject.optInt("code") == 0) {
                    JSONObject object = jsonObject.optJSONObject("data");
                    etName.setText(object.optString("barbershop_name"));
                    etNick.setText(object.optString("barbershop_text"));
                    etPhpone.setText(object.optString("barbershop_tel"));
                    etAdress.setText(object.optString("barbershop_address"));
                }
            }

            @Override
            public void errorHttp(String msg) {
                dismissDiaLog();
            }
        });
    }

    @OnClick(R.id.btn_save)
    public void onClick() {
        showDiaLog("正在修改数据");
        Map<String, String> map = new HashMap<>();
        map.put("access_token", CommonUtils.getToken(ShopManagerInfoActivity.this));
        map.put("barbershop_id", CommonUtils.getShopId(ShopManagerInfoActivity.this));
        map.put("barbershop_text", etNick.getText().toString());
        map.put("barbershop_tel", etPhpone.getText().toString());

        HttpUtils.postHttp(map, CommonConstant.upbarbenshoinfo, new HttpUtils.HttpCallBack() {
            @Override
            public void successHttp(JSONObject jsonObject, int id) {
                dismissDiaLog();
                toastLong(jsonObject.optString("msg"), 0);
                if (jsonObject.optInt("code") == 0) {
                    finish();
                }
            }

            @Override
            public void errorHttp(String msg) {
                dismissDiaLog();
            }
        });
    }
}
